package com.yanxinim.cn.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanxinim.cn.R;
import com.yanxinim.cn.bean.redpacket.BankCardBean;
import com.yanxinim.cn.call.CustomOnItemClickListener;

/**
 * @ClassName BankCardSelectAdapter
 * @Description 银行卡选择列表适配器
 * @Author ChenXL
 * @Date 2021/5/25 19:57
 * @Version 1.0
 */
public class BankCardSelectAdapter extends BaseListAdapter{

    LayoutInflater mInflater;

    CustomOnItemClickListener onItemClickListener;

    public BankCardSelectAdapter(Context ctx) {
        super(ctx);
        mInflater = LayoutInflater.from(ctx);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_bank_card_selectr, parent, false);
            holder = new ViewHolder();
            holder.tvBankName = (TextView) convertView.findViewById(R.id.tvBankName);
            holder.tvBankCardNo = (TextView) convertView.findViewById(R.id.tvBankCardNo);
            holder.ivSelect = (ImageView) convertView.findViewById(R.id.ivSelect);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvBankName.setText(((BankCardBean)datas.get(position)).getBankName().substring(0, 2));
        String cardNo = ((BankCardBean)datas.get(position)).getBankCardNo();
        String cardNoStr = "····  ····  ····  " + cardNo.substring(cardNo.length() - 4, cardNo.length());
        holder.tvBankCardNo.setText(cardNoStr);
        holder.ivSelect.setVisibility(((BankCardBean)datas.get(position)).isSelect() ? View.VISIBLE : View.INVISIBLE);
        return convertView;
    }

    class ViewHolder {
        TextView tvBankName;
        TextView tvBankCardNo;
        ImageView ivSelect;
    }

    public void setOnItemClickListener(CustomOnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    /**
     * 获取银行logo
     */
    public static int getBankLogo(String bankCode){
        int imageId = 0;
        switch (bankCode){
            case "CEB":
                imageId = R.drawable.bank_logo_ceb;
                break;
            case "PSBC":
                imageId = R.drawable.bank_logo_psbc;
                break;
            case "ABC":
                imageId = R.drawable.bank_logo_abc;
                break;
            case "SHYH":
                imageId = R.drawable.bank_logo_shyh;
                break;
            case "CCB":
                imageId = R.drawable.bank_logo_ccb;
                break;
            case "BOCO":
                imageId = R.drawable.bank_logo_boco;
                break;
            case "SDB":
                imageId = R.drawable.bank_logo_sdb;
                break;
            case "HXB":
                imageId = R.drawable.bank_logo_hxb;
                break;
            case "CMBC":
                imageId = R.drawable.bank_logo_cmbc;
                break;
            case "BOC":
                imageId = R.drawable.bank_logo_boc;
                break;
            case "ICBC":
                imageId = R.drawable.bank_logo_icbc;
                break;
            case "CITIC":
                imageId = R.drawable.bank_logo_citic;
                break;
            case "SPDB":
                imageId = R.drawable.bank_logo_spdb;
                break;
            case "CIB":
                imageId = R.drawable.bank_logo_cib;
                break;
            case "CGB":
                imageId = R.drawable.bank_logo_cgb;
                break;
            case "CMBCHINA":
                imageId = R.drawable.bank_logo_cmbchina;
                break;
            case "BCCB":
                imageId = R.drawable.bank_logo_bccb;
                break;
            default:
                break;
        }
        return imageId;
    }
}
